package com.villaday.idf.base;

import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.os.Bundle;
import androidx.appcompat.app.AppCompatActivity;
import android.view.View;

import com.umeng.analytics.MobclickAgent;
import com.villaday.idf.AppManager;
import com.villaday.idf.base.broadcast.RxManager;

import butterknife.ButterKnife;
import butterknife.Unbinder;
import me.bakumon.statuslayoutmanager.library.OnStatusChildClickListener;
import me.bakumon.statuslayoutmanager.library.StatusLayoutManager;

/**
 * 所有Activity的基类
 */
public abstract class BaseNoWhiteActivity extends AppCompatActivity {

    private Unbinder unbinder;
    //RxJava事件总线
    public RxManager mRxManager;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        mRxManager=new RxManager();

        /*//8.1不能使用透明主题
        if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES. O) {

            this.setTheme(R.style.NoTransparent);//不透明

        }else {

            this.setTheme(R.style.Transparent);//透明主题

        }*/
        setContentView(getViewResId());
//        ActivityStackManager.getManager().addActivity(this);
        // 添加Activity到堆栈
        AppManager.getAppManager().addActivity(this);
      //  getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);

      //  StatusBarUtils.setStatusBarLightMode(this, Color.WHITE);
        //8.1不能使用透明主题


            setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);//手机竖屏



        unbinder = ButterKnife.bind(this);
        init();
        loadData();








    }

    //页面跳转
    public void startActivity(Class<?> clz) {
        startActivity(new Intent(BaseNoWhiteActivity.this, clz));
//        overridePendingTransition(R.anim.push_out_right, R.anim.push_out_left);
    }

    /**
     * 带数据的页面跳转
     * @param clz
     * @param bundle
     */
    public void startActivity(Class<?> clz, Bundle bundle) {
        Intent intent = new Intent(BaseNoWhiteActivity.this, clz);
        intent.putExtras(bundle);
        startActivity(intent);
//        overridePendingTransition(R.anim.push_out_right, R.anim.push_out_left);
    }

  /*  @Override
    protected void onSaveInstanceState(Bundle outState) {
        super.onSaveInstanceState(outState);
    }*/

    protected abstract int getViewResId();

    protected void init() {
    }

    protected void loadData() {
    }

    @Override
    protected void onDestroy() {
//        ActivityStackManager.getManager().remove(this);
        // 结束Activity&从堆栈中移除
        AppManager.getAppManager().finishActivity(this);
        unbinder.unbind();
        if (mRxManager!=null){
            mRxManager.clear();
        }
        super.onDestroy();
    }

    public void onResume() {
        super.onResume();
        MobclickAgent.onResume(this);
    }
    public void onPause() {
        super.onPause();
        MobclickAgent.onPause(this);
    }

    public StatusLayoutManager setupDefaultStatusLayoutManager(View rootView, OnStatusChildClickListener onStatusChildClickListener) {
        StatusLayoutManager statusLayoutManager = new StatusLayoutManager.Builder(rootView)

                // 设置默认布局属性
//                .setDefaultEmptyText("空白了，哈哈哈哈")
//                .setDefaultEmptyImg(R.mipmap.ic_launcher)
//                .setDefaultEmptyClickViewText("retry")
//                .setDefaultEmptyClickViewTextColor(getResources().getColor(R.color.colorAccent))
//                .setDefaultEmptyClickViewVisible(false)
//
//                .setDefaultErrorText(R.string.app_name)
//                .setDefaultErrorImg(R.mipmap.ic_launcher)
//                .setDefaultErrorClickViewText("重试一波")
//                .setDefaultErrorClickViewTextColor(getResources().getColor(R.color.colorPrimaryDark))
//                .setDefaultErrorClickViewVisible(true)
//
//                .setDefaultLayoutsBackgroundColor(Color.WHITE)

                // 自定义布局
//                .setLoadingLayout(inflate(R.layout.layout_loading))
//                .setEmptyLayout(inflate(R.layout.layout_empty))
//                .setErrorLayout(inflate(R.layout.layout_error))
//
//                .setLoadingLayout(R.layout.layout_loading)
//                .setEmptyLayout(R.layout.layout_empty)
//                .setErrorLayout(R.layout.layout_error)
//
//                .setEmptyClickViewID(R.id.tv_empty)
//                .setErrorClickViewID(R.id.tv_error)

                // 设置重试事件监听器
                .setOnStatusChildClickListener(onStatusChildClickListener)
                .build();

        return statusLayoutManager;
    }
}
